package com.ok.cartoon.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ok.cartoon.domain.dto.OkCartoonDto;
import com.ok.cartoon.domain.po.OkCartoon;
import com.ok.cartoon.domain.po.OkCartoonCategory;
import com.ok.cartoon.service.IOkCartoonCategoryService;
import com.ok.cartoon.service.IOkCartoonService;
import com.ok.common.domain.po.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 漫画表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-28
 */
@Api(tags = "漫画相关接口")
@RestController
@RequestMapping("/cartoon")
@RequiredArgsConstructor
public class OkCartoonController {

    private final IOkCartoonService okCartoonService;

    @ApiOperation(value = "添加漫画")
    @PostMapping("/add")
    public Result add(@RequestBody OkCartoonDto okCartoonDto){
        okCartoonService.add(okCartoonDto);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "删除漫画")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        okCartoonService.delete(id);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "修改漫画")
    @PutMapping("/update")
    public Result update(@RequestBody OkCartoonDto okCartoonDto){
        okCartoonService.updateWith(okCartoonDto);
        return Result.success("修改成功");
    }

    @ApiOperation(value = "分页查询漫画")
    @GetMapping("/page")
    public Result page(@RequestParam Integer pageNo,
                       @RequestParam Integer pageSize,
                       @RequestParam(required = false) Integer categoryId,
                       @RequestParam(required = false) Integer areaId
    ){
        Page<OkCartoon> page = okCartoonService.pageWith(pageNo, pageSize, categoryId, areaId);
        return Result.success(page);
    }

    @ApiOperation(value = "es分页查询漫画数据")
    @GetMapping("/pageEs")
    public Page pageEs(@RequestParam Integer pageNo, @RequestParam Integer pageSize){
        Page<OkCartoon> pageInfo = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<OkCartoon> queryWrapper = new LambdaQueryWrapper<>();
        okCartoonService.page(pageInfo,queryWrapper);
        return pageInfo;
    }

}
